/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Core;
using NUnit.Framework;

namespace Madason.MetaModel.Interfaces.Tests
{
	[TestFixture]
	public class TestImportStarUmlClassmember : TestImportStarUmlBase
	{
		
		[Test]
		public void TestLoadAttribute()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Assert.AreEqual(3, cls.Attributes.Count);
		}

		[Test]
		public void TestCheckAttributeName()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Attribute attrA = cls.Attributes["AttributeA"];
			Attribute attrB = cls.Attributes["AttributeB"];
			Assert.IsNotNull(attrA, "Can't find AttributeA");
			Assert.IsNotNull(attrB, "Can't find AttributeB");
			Assert.AreEqual("DaJAviko+U6TiW4mz0HomgAA", attrA.Id);
		}

		[Test]
		public void TestCheckAttributeType()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Class cls2 = model.FindClassByName("Tests.Child.ClassWithTaggedValue");
			Assert.IsNotNull(cls);
			Attribute attrA = cls.Attributes["AttributeA"];
			Attribute attrB = cls.Attributes["AttributeB"];
			Attribute attrC = cls.Attributes["AttributeC"];

			Assert.IsNotNull(attrA.Type, "AttributeA missing Type");
			Assert.IsNotNull(attrB.Type, "AttributeB missing Type");
			Assert.IsNotNull(attrC.Type, "AttributeC missing Type");
			Assert.AreEqual("int", attrA.Type.Name);
			Assert.AreEqual("string", attrB.Type.Name);
			Assert.AreEqual("ClassWithTaggedValue", attrC.Type.Name);
			Assert.AreEqual(cls2.Id, attrC.Type.Id);
		}

		[Test]
		public void TestAttributeStereotype()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Attribute attrA = cls.Attributes["AttributeA"];
			Assert.AreEqual(Stereotype.PrimaryKey, attrA.Stereotype);
		}



		[Test]
		public void TestLoadOperation()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.IsNotNull(op, "missing OperationA");
			Assert.AreEqual("FTMi06Sqa0m6sUDvZjFIRwAA", op.Id);
		}

		[Test]
		public void TestOperationParameter()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.IsNotNull(op, "missing OperationA");
			Assert.AreEqual(1, op.Parameters.Count);
		}


		[Test]
		public void TestOperationParameterName()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.IsNotNull(op, "missing OperationA");

			Assert.AreEqual("a", op.Parameters[0].Name);
		}


		[Test]
		public void TestOperationParameterType()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.IsNotNull(op, "missing OperationA");

			Assert.IsNotNull(op.Parameters[0].Type);
			Assert.AreEqual("int", op.Parameters[0].Type.Name);
		}

		[Test]
		public void TestOperationParameterDir()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationB"];
			Assert.IsNotNull(op, "missing OperationB");

			
			Assert.AreEqual(ParameterDir.Out, op.Parameters[0].Dir);
		}


		[Test]
		public void TestOperationParameterReturnType()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.IsNotNull(op, "missing OperationA");
			Assert.IsNotNull(op.ReturnType);
			Assert.AreEqual("string", op.ReturnType.Name);
		}

		[Test]
		public void TestOperationStereotype()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.AreEqual("Finder", op.StereotypeName);
		}


		[Test]
		public void TestOperationTaggedValue()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Operation op = cls.Operations["OperationA"];
			Assert.AreEqual("SELECT", op.TaggedValues["sql"]);
		}

		[Test]
		public void TestAttributeTaggedValue()
		{
			Model model = LoadModelFromResource("TestModel.uml");
			Class cls = model.FindClassByName("Tests.Child.ClassWithMember");
			Assert.IsNotNull(cls);
			Attribute attr = cls.Attributes["AttributeA"];
			Assert.AreEqual("col", attr.TaggedValues["column"]);
		}
	}
}
